Skip to content

Generate and load JavaScript translation catalogs - #338

Open
m-aciek wants to merge 4 commits into
python:mainfrom
m-aciek:js-copy-button-translations
Open

m-aciek wants to merge 4 commits into
python:mainfrom
m-aciek:js-copy-button-translations

Conversation

@m-aciek

@m-aciek m-aciek commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

Alternative to #337.

Add and mount missing JS translations catalog. Extraction was/is working correctly.

@read-the-docs-community

read-the-docs-community Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 python-docs-theme-previews | 🛠️ Build #36116487 | 📁 Comparing fb80b82 against latest (db635c1)

  🔍 Preview build  

145 files changed · + 1 added · ± 144 modified

+ Added

± Modified

@m-aciek
m-aciek marked this pull request as ready for review November 21, 2026 22:46
Comment thread babel_runner.py Resolved
Comment thread pyproject.toml Resolved
…rtifact paths alphabetically in pyproject.toml
Comment thread babel_runner.py Outdated
Comment on lines +124 to +129
"""Export translated singular JavaScript messages from the compiled catalog."""
mofile = pofile.with_suffix(".mo")
jsfile = pofile.with_suffix(".js")
if not mofile.exists():
jsfile.unlink(missing_ok=True)
return

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could simplify this function to only read the .po file, and skip the fuzzy/untranslated messages, rather than also reading the compiled .mo file?

Suggested change
"""Export translated singular JavaScript messages from the compiled catalog."""
mofile = pofile.with_suffix(".mo")
jsfile = pofile.with_suffix(".js")
if not mofile.exists():
jsfile.unlink(missing_ok=True)
return
"""Export translated singular JavaScript messages from the catalog."""
jsfile = pofile.with_suffix(".js")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for suggestion, applied. On the other hand using .mo makes us reusing the same configuration of catalog compilation, but it's not worth the complication probably.

Comment thread babel_runner.py Outdated
Comment on lines +132 to +133
with mofile.open("rb") as f:
compiled = read_mo(f)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
with mofile.open("rb") as f:
compiled = read_mo(f)

Comment thread babel_runner.py Outdated
compiled = read_mo(f)
messages = {}
for message in source:
if not isinstance(message.id, str):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if not isinstance(message.id, str):
if not isinstance(message.id, str) or message.fuzzy or not message.string:

Comment thread babel_runner.py Outdated
Comment on lines +140 to +142
translation = compiled.get(message.id)
if translation is not None and translation.string:
messages[message.id] = translation.string

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
translation = compiled.get(message.id)
if translation is not None and translation.string:
messages[message.id] = translation.string
messages[message.id] = message.string

Comment thread babel_runner.py Outdated
import tomllib
from pathlib import Path

from babel.messages.mofile import read_mo

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from babel.messages.mofile import read_mo

@tomasr8

tomasr8 commented Nov 22, 2026

Copy link
Copy Markdown
Member

Thanks for doing the work @m-aciek! I should have time tomorrow for a review :)

Comment thread babel_runner.py Outdated
compiled = read_mo(f)
messages = {}
for message in source:
if not isinstance(message.id, str):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if not isinstance(message.id, str):
if message.pluralizable:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Comment thread babel_runner.py Outdated
compiled = read_mo(f)
messages = {}
for message in source:
if not isinstance(message.id, str):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to warn/raise for ngettext/pgettext or just silently skip them?

@m-aciek m-aciek Nov 23, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added support for ngettext in fb80b82 by using addTranslations instead of raw dictionary. pgettext is not supported by extraction edit: JS gettext runtime, so it should be not worth to warn. Thanks for the review.

Affirm-Session: 01a20a8a-1869-7c52-8e68-246dde4499c5
Affirm-Session: 01a20a8a-1869-7c52-8e68-246dde4499c5

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants